package com.hxzy.config.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hxzy.config.security.SecurityUtil;
import com.hxzy.dto.AdminLoginDTO;
import com.hxzy.vo.AdminLoginVO;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-plus自动填充功能
 */
@Component
public class FillMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
       // AdminLoginVO adminLoginVO= NewBeeThreadLocal.adminLoginVOThreadLocal.get();
        //AdminLoginVO  adminLoginVO= (AdminLoginVO) SecurityContextHolder.getContext().getAuthentication();


        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject,"createBy",String.class, SecurityUtil.getLoginName());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
       // AdminLoginVO adminLoginVO= NewBeeThreadLocal.adminLoginVOThreadLocal.get();
       // AdminLoginVO  adminLoginVO= (AdminLoginVO) SecurityContextHolder.getContext().getAuthentication();

        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date()); // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject,"updateBy",String.class, SecurityUtil.getLoginName());
    }
}
